import os
import sys
d = os.path.dirname(__file__)
parent_path = os.path.dirname(d)
sys.path.append(parent_path)
from ulits import fstool


class Store_se(object):
    def __init__(self ,seller_id):
        self.seller_id = seller_id
        self.extc_s = fstool.Excel(parent_path+'/data'+'/store.xls')
        self.seller = fstool.Excel(parent_path+'/data'+'/seller.xls')
    def seek(self):
        list_stor = self.extc_s.read_all_data('store')
        return list_stor
    def seek_carge(self):#查询
        list_stor = self.seek()
        sel_st = []
        for i in list_stor:
            if  i[-2] == self.seller_id:
                sel_st.append(i)
        if  len(sel_st) != 0:
            for i in sel_st:
                print('编号：%d   商品名称：%s   商品数量：%s   商品价格：%s'%(i[0],i[1],i[2],i[3]))
        else:
            print('库存为空！') 
            return False
        return True
    def add_carge(self):#增添库存
        list_stor = self.seek()
        if list_stor[-1][0] != '库存ID':
            obj=[]
            obj.append((list_stor[-1][0])+1)
            for i in list_stor[0][1:4]:
                ss = input('请输入%s：'%i)
                obj.append(ss)
            obj.append(self.seller_id)
            for i in self.seller.read_all_data('seller'):
                if i[0] == self.seller_id:
                    obj.append(i[1])
            self.extc_s.write_row_data(obj ,'store')
        else:
            obj=[]
            obj.append(1)
            for i in list_stor[0][1:4]:
                ss = input('请输入%s：'%i)
                obj.append(ss)
            obj.append(self.seller_id)
            for i in self.seller.read_all_data('seller'):
                if i[0] == self.seller_id:
                    obj.append(i[1])
            self.extc_s.write_row_data(obj ,'store')

    def remove_carge(self):#删除库存
        glob = self.seek_carge()
        if glob:
            ss = input('请输入你要删除库存的编号：')
            self.extc_s.delete_row_data(ss ,'store')

    def amend_carge(self):#修改
        glob = self.seek_carge()
        if glob:
            ss = int(input('请输入你要修改库存的编号：'))
            A = ['商品名称' ,'商品数量' ,'商品单价']
            biaotou = fstool.show(A)
            sss = A [int(biaotou)-1]
            ss1 = input('请输入你要修改成：')
            obj = {'库存ID':ss,sss:ss1}
            self.extc_s.write_cell_data(obj ,'store')



if __name__ == '__main__':  
    store_se = Store_se('09876543210')
    # store_se.add_carge()
    # store_se.seek_carge()
    store_se.remove_carge()
    # store_se.amend_carge()
    # print(store_se.seek())
